<template>
  <div class="container_detail user-edit">
    <div class="header">
      <p v-if="type">定制用户管理>查看定制用户</p>
      <p v-else>用户管理>查看用户</p>
      <el-button class="link" type="primary">
        <router-link :to="{path:'userList',query: { pageIndex: currentPage }}" style="color: #fff;">返回</router-link>
      </el-button>
    </div>
    <div class="main">
      <el-form :model="user" :rules="rules" ref="user" label-width="120px" class="">
        <div v-if="!type" class="list">
          <div class="title">查看用户</div>
          <el-form-item prop="goodsName">
            <div class="item">
              <div class="item-key">头像:</div>
              <div class="item-value">
                <img style="width:80px;height:80px;border-radius:50%" :src="user.weixinUserCoreDTO?user.weixinUserCoreDTO.headimgurl:'../../images/default.png'" alt="">
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="price">
            <div class="item">
              <div class="item-key">用户名:</div>
              <div class="item-value">
                {{user.weixinUserCoreDTO?user.weixinUserCoreDTO.weixinUsername:''}}
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="price">
            <div class="item">
              <div class="item-key">用户手机号:</div>
              <div class="item-value">
                {{user.mobile}}
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="price">
            <div class="item">
              <div class="item-key">账户余额:</div>
              <div class="item-value">
                {{user.price}}
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="price">
            <div class="item">
              <div class="item-key">绑定的卡券/所属单位:</div>
              <div class="item-value">
                {{coupinName}}
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="price">
            <div class="item">
              <div class="item-key">消费记录:</div>
              <div class="item-value">
                <div v-for="(item,index) in user.payOrderDTOS" :key="index">
                  {{item.gmtCreated}}  {{item.esPayOrderDetailDTO[0].goodsName}}    ¥{{item.totalPrice}}
                </div>
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="price">
            <div class="item">
              <div class="item-key">收货记录:</div>
              <div class="item-value">
                <div v-for="(item,index) in user.payOrderDTOS" v-if="item.orderType == 'real'" :key="index">
                  {{item.trueName}} {{item.mobile}} {{item.address}}
                </div>
              </div>
            </div>
          </el-form-item>
        </div>
        <div v-if="type" class="list">
          <el-form-item prop="price">
            <div class="item">
              <div class="item-key">账号:</div>
              <div class="item-value">
                {{user.userName}}
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="price">
            <div class="item">
              <div class="item-key">密码:</div>
              <div class="item-value">
                {{user.psw}}
              </div>
            </div>
          </el-form-item>
           <el-form-item prop="price">
            <div class="item">
              <div class="item-key">余点:</div>
              <div class="item-value">
                {{user.price}}
              </div>
            </div>
          </el-form-item>
           <el-form-item prop="price">
            <div class="item">
              <div class="item-key">所属集团:</div>
              <div class="item-value">
                {{user.trueName}}
              </div>
            </div>
          </el-form-item>
           <el-form-item prop="price">
            <div class="item">
              <div class="item-key">有效期:</div>
              <div class="item-value">
                 {{user.validTime?user.validTime.split(' ')[0]:'--'}}
              </div>
            </div>
          </el-form-item>
           <el-form-item prop="price">
            <div class="item">
              <div class="item-key">使用范围-公开商品:</div>
              <div class="item-value">
                {{user.select}}
              </div>
            </div>
          </el-form-item>
          <el-form-item prop="price">
            <div class="item">
              <div class="item-key">使用范围-非公开商品:</div>
              <div class="item-value">
                {{user.noSelect}}
              </div>
            </div>
          </el-form-item>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
let CONSTANT = require("../../constant/constant.js");
let common = require("../../common.js");
let countryArr = require("../../../static/city.json");
export default {
  data() {
    return {
      id: "",
      info: "",
      // 返回 导航页码
      currentPage: 1,
      coupinName:'',
      user: {},
      rules:{},
     typeArr:[
        {
            name:'实体商品',
            value:'real'
        },
         {
            name:'自营电子券',
            value:'virtual'
        },
        {
            name:'第三方电子券',
            value:'third'
        }
      ],
      brandArr:[],
      sortArr:[],
      provinceArr :[],
      cityArr:[],
      type:''
    };
  },
  mounted() {
    this.type = this.$router.currentRoute.query.type;
    this.provinceArr = countryArr.provinces.province,
    this.id = this.$router.currentRoute.query.id;
    this.currentPage = this.$router.currentRoute.query.pageIndex
      ? this.$router.currentRoute.query.pageIndex
      : 1;
    this.getDetail();
  },
  methods: {
    returnName(val){
        let str;
        this.typeArr.map(item=>{
            if(item.value == val){
                str = item.name
            }
        })
        return str
    },
    getDetail() {
      let url = CONSTANT.URL.LIST.findEsShopUserCoreById;
      let data = { id: this.id }
      common.requestAjax(url, JSON.stringify(data), null, res => {
        let data = res.data.bussData;

        if(this.type){
          let arr = []
          data.nEsGoodsSelect.map(item=>{
            arr.push(item.goodsName)
          })
          let arr1 = []
          data.yEsGoodsSelect.map(item=>{
            arr1.push(item.goodsName)
          })
          data.select = arr1.join(',')
          data.noSelect = arr.join(',')
        }
        let arrS = []
        if(data.couponDTOS){
           data.couponDTOS.map(item=>{
            if(data.type == 'normal'){
              arrS.push(item.couponCode)
            }else if(data.type == 'special'){
              arrS.push(item.trueName)
            }
        })
        }
       
        this.coupinName = arrS.join('、')
        this.user = data
      });
    }
  }
};
</script>
<style lang="scss">
.user-edit {
  .el-form-item {
    margin: 0px;
    
  }

  .item-value {
    word-break: break-all;
    .el-input {
      width: 50%;
    }
    .el-select {
      width: 50%;
      .el-input {
        width: 100%;
      }
    }
  }
  .el-form-item__content {
    margin: 0px !important;
  }
}
</style>

